package com.rent.message.ws;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.messaging.SessionDisconnectEvent;

/*
* 监听Session断开事件
* 删除用户会话
* 删除用户映射
* 删除用户UUID映射
 */
@Component
public class WebSocketEventListener {
    
    @Autowired
    private MessageSessionService sessionService;
    
    @EventListener
    public void handleWebSocketDisconnectListener(SessionDisconnectEvent event) {
        String sessionId = event.getSessionId();
        sessionService.removeSession(sessionId);
    }
}